package com.devunion.salon.dataload;

import org.springframework.context.ApplicationContext;
import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import com.devunion.salon.core.model.security.Privilege;

import javax.persistence.EntityManager;

/**
 * @author spetrakovsky
 */
public class PrivilegesLoader implements EntityLoader {

    private List<String> privileges;

    @Transactional
    public void loadEntityes(ApplicationContext context, EntityManager em) {
        if (privileges != null) {
            for (String name : privileges) {
                Privilege privilege = new Privilege();
                privilege.setName(name);
                em.persist(privilege);
            }
        }
    }

    public List<String> getPrivileges() {
        return privileges;
    }

    public void setPrivileges(List<String> privileges) {
        this.privileges = privileges;
    }
}
